'use client'
import React from 'react'
import Link from 'next/link'
import { Button, message } from 'antd'
import { useRouter } from 'next/navigation'

const Page = () => {
  const router = useRouter()
  const [messageApi, contextHolder] = message.useMessage()
  
  const handleLogout = async () => {
    const res = await fetch('/api/logout', {
      method: 'POST',
      headers: {
        'Content-Type': 'application/json'
      },
    })
    
    const data = await res.json()
    
    if (data.code !== 200) {
      messageApi.error(data.msg).then()
    } else {
      router.push('/login')
    }
  }
  
  return (
    <div className="container mx-auto flex justify-center items-center gap-6 h-screen">
      {contextHolder}
      这个页面需要登录才能访问
      <Button type="primary" onClick={handleLogout}>退出登录</Button>
      <Link href={'/'} className="text-blue-400">回到首页</Link>
    </div>
  )
}

export default Page
